<include file="public:head" />
<style type="text/css">
  .layui-progress , .layui-progress-bar{border-radius: 0px;}
  .layui-upload-drag{padding: 30px 0px;}
</style>
<!-- 二级页次级导航 -->
<div class="layui-hide-xs">
  <div class="fly-panel fly-column">
    <div class="layui-container">
      <span class="layui-breadcrumb">
        <a href="{:C('wkcms_site_url')}">首页</a>
        <a href="">上传文档</a>
      </span>
      <div class="fly-column-right layui-hide-xs"> 
        <span class="fly-search"><i class="layui-icon"></i></span> 
        <a href="{:U('doc/doc_share')}" class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe681;</i> 上传文档</a> 
      </div> 
    </div>
  </div>
</div>
<!-- 二级页次级导航结束 -->

<!-- 主体开始 -->
<div class="layui-container">
    <div class="layui-row layui-col-space15">
        <!-- 左侧开始 -->
        <div class="layui-col-md9 content detail">
            <div class="fly-panel fly-panel-user" pad20>
                <div class="layui-tab layui-tab-brief" >
                  <ul class="layui-tab-title">
                    <li class="layui-this"><a href="{:U('doc/doc_share')}">上传单个文档</a></li>
                    <li><a href="{:U('doc/doc_batch_share')}">批量上传工具</a></li>
                  </ul>
                </div>
                <!-- 上传部分开始 -->
                <form method="post" class="layui-form layui-form-pane" enctype="multipart/form-data">
                <input type="hidden" name="fileurl"  id="fileurl"  size="30" value="{$info.fileurl}">
                <input type="hidden" name="ext"  id="ext"  size="30" value="{$info.ext}">
                <input type="hidden" name="filesize"  id="filesize"  size="30" value="{$info.filesize}">
                <input type="hidden" name="oldname"  id="oldname"  size="30" value="{$info.oldname}">
                <input type="hidden" name="hash"  id="hash"  size="30" value="{$info.hash}">
                <input type="hidden" name="viewurl"  id="viewurl"  size="30" value="">
                <input type="hidden" name="cateid" id="J_cate_id" value="" />
                <div class="layui-form-item" style="margin-top: 15px;">
                  <div class="layui-input-block" style="margin-left:0px;">
                      <div class="upfile">
                        <div class="layui-upload-drag" id="upfile">
                          <i class="layui-icon"></i>
                          <p>点击上传，或将文件拖拽到此处</p>
                        </div>
                        <div class="layui-progress" lay-showpercent="true" lay-filter="demo" >
                          <div class="layui-progress-bar" lay-percent=""></div>
                        </div>
                      </div>
                  </div>
                </div> 
                <div class="layui-form-item" style="margin-top: 15px;">
                  <label class="layui-form-label">文档标题</label>
                  <div class="layui-input-block">
                    <input type="text" class="layui-input" name="title" id="title" lay-verify="title"  placeholder="请填写文档标题！">
                  </div>
                </div>
                <div class="layui-form-item" >
                  <label class="layui-form-label">文档售价</label>
                  <div class="layui-input-block">
                    <input type="number" class="layui-input" name="score" id="score" value="0" placeholder="请填写售价，只能是数字！">
                  </div>
                </div>
                <div class="layui-form-item" >
                  <label class="layui-form-label">文档标签</label>
                  <div class="layui-input-block">
                    <input type="text" class="layui-input" name="tags" id="tags" lay-verify="title" placeholder="可填写多个,以英文都好分割！" >
                    <span class="layui-btn layui-btn-xs layui-bg-blue" id="J_gettags" style="margin-top: 5px;">自动获标签</span>
                  </div>
                </div>
                <div class="layui-form-item" >
                  <label class="layui-form-label">文档简介</label>
                  <div class="layui-input-block">
                    <textarea placeholder="请输入文档简介" name="intro" class="layui-textarea"></textarea>
                  </div>
                </div>
                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">文档分类</label>
                    <div class="layui-input-inline">
                      <select id="groupcateid" class="J_cate_select" multiple="multiple" lay-ignore >
                        <option disabled>请选择一级分类</option>
                        <volist name="catlist" id="vo">
                          <option value="{$vo.id}">{$vo.name}</option>
                        </volist>
                      </select>
                    </div>
                  </div>
                  <div class="layui-inline">
                    <div class="layui-input-inline">
                      <select name="tid" id="tid" class="J_cate_select" multiple="multiple" lay-ignore>
                        <option disabled>请选择二级分类</option>
                      </select>
                    </div>
                  </div>
                </div>
                <div class="layui-form-item" >
                   <div class="layui-input-block">
                    <a class="layui-btn" lay-submit="" lay-filter="upbtn"> 发布文档 </a> 
                    <span style="float: right;">
                      <input type="checkbox" id="agree" name="like1[write]" lay-skin="primary" checked="checked">
                     <a href="{:U('page/index',array('id'=>6))}" target="_blank" style="position: relative; top: 4px; left: 5px; color: #999;">同意文档发布协议</a>
                    </span>
                  </div>
                </div>


                </form>
                <!-- 上传部分结束 -->
            </div>
        </div>
        <!-- 左侧结束 -->

        <!-- 右侧开始 -->
        <div class="layui-col-md3 ">
            <!-- 客服开始 -->
            <div class="fly-panel">
                <h3 class="fly-panel-title">遇到问题，联系客服免费帮您解决</h3>
                <div class="fly-panel-main">
                  <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&amp;uin={:C('wkcms_site_qq')}&amp;site=qq&amp;menu=yes" class="fly-zanzhu">联系QQ客服  {:C('wkcms_site_qq')}</a>
                  <h3 style="margin-top: 10px; text-align: center;">全国免长途电话：{:C('wkcms_site_tel')}</h3>
                </div>
            </div>
            <!-- 客服结束 -->
            <!-- 广告 -->
            <div class="fly-panel">
                <div class="fly-panel-main">
                   {:R('advert/index', array(11), 'Widget')} 
                </div>
            </div>
              <!-- 广告结束 -->
        </div>
        <!-- 右侧结束 -->
    </div>
</div>
<!-- 主体结束 -->

<include file="public:footer" />
<!-- 网站底部END -->
<script>
//主动加载jquery模块
layui.use(['jquery', 'layer', 'form', 'upload', 'element'],
function() {
    var $ = layui.$,
    layer = layui.layer,
    form = layui.form,
    upload = layui.upload,
    element = layui.element;

    //创建监听函数
    var xhrOnProgress = function(fun) {
        xhrOnProgress.onprogress = fun; //绑定监听
        //使用闭包实现监听绑
        return function() {
            //通过$.ajaxSettings.xhr();获得XMLHttpRequest对象
            var xhr = $.ajaxSettings.xhr();
            //判断监听函数是否为函数
            if (typeof xhrOnProgress.onprogress !== 'function') return xhr;
            //如果有监听函数并且xhr对象支持绑定时就把监听函数绑定上去
            if (xhrOnProgress.onprogress && xhr.upload) {
                xhr.upload.onprogress = xhrOnProgress.onprogress;
            }
            return xhr;
        }
    }

    //执行实例
    var uploadInst = upload.render({
        elem: '#upfile' //绑定元素
        ,
        field: 'Filedata',
        url: '{$uploadimgurl}' //上传接口
        ,
        accept: 'file' //普通文件
        ,
        exts: 'doc|docx|xls|xlsx|pptx|ppt|wps|et|pdf|txt' //允许后缀
        ,
        xhr: xhrOnProgress,
        choose: function(obj) {
            element.progress('demo', value = '0%');
        },
        progress: function(value) {

            $('.layui-progress-bar').removeClass('layui-bg-red');

            element.progress('demo', value + '%') //设置页面进度条
        },
        done: function(data) {

            //上传完毕回调
            if (data.status == 1) {
                layer.msg('上传成功', {
                    time: 1800
                },
                function() {
                    $('#fileurl').val(data.info.name);
                    $('#oldname').val(data.info.oldname);
                    $('#title').val(data.info.oldname);
                    $('#upinfo').html(data.info.oldname + "." + data.info.ext);
                    $('#filesize').val(data.info.size);
                    $('#viewurl').val(data.info.ycname);
                    $('#hash').val(data.info.hash);
                    //$('#tags').val(data.info.ext);
                    $('#ext').val(data.info.ext);
                    $('#J_gettags').click();
                    element.progress('demo', value = '100%');
                    $('.dengdai').addClass('hidden');
                    $('.shibai').addClass('hidden');
                    $('.chenggong').removeClass('hidden');

                    $('.chenggong p').html(data.info.oldname + '上传成功');

                });
            } else {
                layer.msg(data.info, {
                    time: 1800
                });
                $('.layui-progress-bar').addClass('layui-bg-red');
                $('.dengdai').addClass('hidden');
                $('.shibai').removeClass('hidden');
                $('.shibai p').html(data.info);
                $('#oldname').val();
            }
        },
        error: function() {
            layer.msg("网络异常，请尝试重新上传！", {
                time: 1800
            });
            element.progress('demo', value = '网络异常，请尝试重新上传');
            $('.layui-progress-bar').addClass('layui-bg-red');
        }
    });

    //获取自动标签
    $('#J_gettags').on('click',
    function() {
        var title = $.trim($('#title').val());
        if (title == '') {
            layer.msg("请先上传文档，或输入文档标题！", {
                time: 1800
            });
            return false;
        }
        $.getJSON('{:U("doc/ajax_gettags")}', {
            title: title
        },
        function(result) {
            if (result.status == 1) {
                $('#tags').val(result.data);
            } else {
                $.wkcms.tip({
                    content: result.msg
                });
            }
        });
    });

    //点一级获二级分类
    $('#groupcateid').change(function() {
        loading = layer.msg('请稍后...', {
            icon: 16,
            shade: 0.01
        });        
        var caturl = '{:U("doc_cate/ajax_getsubcate")}&id=' + $(this).val();
        $('#J_cate_id').val($(this).val()); //赋值选中ID
        $.post(caturl,
        function(data) {
          layer.close(loading);
            if (data.status == 1) {
                $('#tid').html('');
                $('#tid').append('<option disabled>请选择二级分类</option>');
                $('#tiddiv').removeClass("disnone");
                for (var i = 0; i < data.data.length; i++) {
                    $('#tid').append('<option value="' + data.data[i]['id'] + '">' + data.data[i]['name'] + '</option>');
                }
            } else {
                //$('#tiddiv').addClass("disnone");
                $('#tid').html('');
            }

        });
    });
    //点二级获三级分类
    $('#tid').change(function() {
        $('#J_cate_id').val($(this).val()); //赋值选中ID
        var caturl = '{:U("doc_cate/ajax_getsubcate")}&id=' + $(this).val();

    });

    //提交
    form.on('submit(upbtn)',
    function(data) {
        var agree = $('#agree').is(":checked");
        if (!agree) {
            layer.msg("请先同意并阅读协议", {
                time: 1800
            });
            return false;
        }
        var title = $.trim($('#title').val());
        if (title == '') {
            layer.msg("请先上传文档", {
                time: 1800
            });
            return false;
        }
        // 提交到方法 默认为本身
        if ($('#J_cate_id').val() == '') {
            layer.msg("请选择文档分类", {
                time: 1800
            });
            return false;
        }

        loading = layer.msg('正在提交，请稍后...', {
            icon: 16,
            shade: 0.01
        });
        $.post("{:U('doc/doc_share',array('type'=>'add'))}", data.field,
        function(res) {
            layer.close(loading);
            if (res.status == 1) {
                layer.msg(res.msg, {
                    time: 1800
                },
                function() {
                    location.href = "{:u('ucenter/mydoclist')}";
                });
            } else {
                layer.msg(res.status.info, {
                    time: 1800
                });
            }
        });
        return true;
    });
}); 
 
</script>
<script>
layui.config({
  version: "3.0.0"
  ,base: '__PUBLIC__/theme/blueideal/mods/' //这里实际使用时，建议改成绝对路径
}).extend({
  fly: 'index'
}).use('fly');
</script>